package yellow.pe.javaVersion;

/**
 * https://pe-cn.github.io/1/
 *
 * Problem 1
 * Multiples of 3 or 5
 * If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. 
 * The sum of these multiples is 23.
 * Find the sum of all the multiples of 3 or 5 below 1000.
 *
*/

public class PE0001 {
    public static void main(String[] args) {

        long sum = 0L;
        for(int i=1; i<1000; i++ ) {
            if(i%3==0 || i%5==0) {
                sum += i;
            }
        }
        System.out.println(sum);

        // 3 6 9 12 15 18 21 24 27 30 .. 999
        //3*(1 2 3 4 5 6 7 8 9 10 .. 333) -> 3*(333*(333+1))/2
        long m3 = 3*(333*(333+1))/2;
        // 5 10 15 20 25 30 35 40 45 50 .. 995
        //5*(1 2 3 4 5 6 7 8 9 10 .. 199) -> 5*(199*(199+1))/2
        long m5 = 5*(199*(199+1))/2;
        // 15 30 45 .. (100 / 15 ~ 66) -> 15*66 -> 990
        //15*(1 2 3 .. 66) -> 15*(66*(66+1))/2;
        long m15 = 15*(66*(66+1))/2;
        System.out.println(m3+m5-m15);

    }
}